import { request } from '@inbiz/utils';


// 索引库的系统分类
export type ISearchData = {
  Code: number;
  SearchTime: number;
  PageCount: number;
  Total: number;
  RawList: {
    HighlightList: object;
    RawData: {
      filename?: string;
      foldername?: string;
      similary?: number;
    };
  }[];
  SectionList: {
    IsGroup: boolean;
    Key: string;
    Sort: number;
    IsWhether: boolean;
    Value: string;
    SectionGroupData: any[];
    IsShowTitle: boolean;
    sectionItemList: {
      Count: number;
      Key: string;
      Value: string;
    }[];
  }[];
};

export function getSearchData(data: {
  KeyWord?: string;
  PageIndex: number;
  PageSize: number;
  IndexName: string;
}): Promise<ISearchData> {
  return request('/search/IndexSearch/GetSearchData', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json; charset=utf-8'
    },
    data
  }).then((data) => {
    if (!data) {
      return {};
    }
    return data;
  });
}
export async function uploadSearchImg(file){
  const formData = new FormData();
  formData.append('file', file);
  return request(`/ImageSearch/Upload`, {
    method: 'POST',
    data: formData,
  });
}

export async function getFiletypes() {
  return request('/WebCore', {
    method: 'post',
    requestType: 'form',
    data: {
      module: 'WebClient',
      fun: 'GetAllFileExtNameList',
    },
  });
}

export async function setImageLink(keyWord: string) {
  return request('/WebCore', {
    method: 'post',
    requestType: 'form',
    data: {
      module: 'MetaDataManager',
      fun: 'SaveSearchData',
      keyWord,
      searchLocation: 'enterprise'
    },
  });
}

export async function getSecretLevels() {
  return request(`/WebCore`, {
    method: 'POST',
    requestType: 'form',
    data: {
      module: 'WebClient',
      fun: 'GetSecLevel',
    },
  });
}